import request from '@/utils/request'

import { ipc } from '@/utils/ipcRenderer';
import { ipcApiRoute, specialIpcRoute } from '@/api/main';

import { getDateStr, getTimeStr } from '@/utils/dateUtils'

function packageBody(deviceCode, body) {
  let header = {
    senddate: getDateStr(),
    sendtime: getTimeStr(),
    devicecode: deviceCode,
    version: '1.0',
    token: 'token',
    serialno: '123456780'
  };
  return {header, body};
}

// 設備簽到
export async function signIn() {
  let body = {};
  // 獲取mac
  let {mac, ip} = await ipc.invoke(ipcApiRoute.getIpAndMacAddr);
  body.deviceip = ip;
  body.devicemac = mac;
  body.systemname = "Windows";
  body.resolution = await ipc.invoke(ipcApiRoute.getScreenResolution);
  body.uuid = await ipc.invoke(ipcApiRoute.getMachineId);
  const data = packageBody('', body);
  return request({
    url: '/httpcommon/signin',
    method: 'post',
    data: data
  })
}
